package com.googlecode.intellimars.sabotter.action;

import com.googlecode.intellimars.sabotter.ui.SabotterPostDialog;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.IconLoader;

public class UpdateStatusAction extends AnAction {
    public UpdateStatusAction() {
      getTemplatePresentation().setIcon(IconLoader.getIcon("/actions/editSource.png"));
    }

    public void actionPerformed(AnActionEvent e) {
        Project project = DataKeys.PROJECT.getData(e.getDataContext());
        if (project != null) {
            // TODO:Twitterにログインしてなかったら動いちゃダメだよね。
            new SabotterPostDialog(project);
        }
    }

    /* TODO:EditorActionだったころの名残を残す
    public UpdateStatusAction() {
        super(new PostHandler());
    }

    private static class PostHandler extends EditorActionHandler {
        public void execute(Editor editor, DataContext dataContext) {
            Project project = DataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(editor.getComponent()));
            // TODO:ポップアップエディタ開くたびに，前回の編集内容が消えるってのはどうかな？
            // TODO:送信するまで残してた方が「ボスが来た」っぽくていいかも
            new SabotterPostDialog(project);
        }
        public boolean isEnabled(Editor editor, DataContext datacontext) {
            Project project = DataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(editor.getComponent()));
            return project != null;
        }
    }
    */
}
